package com.moon.back.service.impl.timer_clear_user_job;

import com.moon.back.constant.RedisConstant;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class ClearUnInLineUserJob {

    @Autowired
    private RedissonClient redissonClient;

    @Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
    public void cleanupLowScores() {
        RScoredSortedSet<String> sortedSet = redissonClient.getScoredSortedSet(RedisConstant.DEV_INLINE_NUM);
        // 删除分数 <= 100 的成员
        int removed = sortedSet.removeRangeByScore(Double.NEGATIVE_INFINITY, Boolean.TRUE, (double) System.currentTimeMillis(), Boolean.FALSE);
        log.info("已清理成员数量: {}", removed);
    }

}
